package com.woniuxy.myfinance.controller;

import com.woniuxy.commons.annotation.RequirePerms;
import com.woniuxy.commons.entity.Inandoutlog;
import com.woniuxy.commons.entity.PageBean;
import com.woniuxy.commons.stafflog.LogRequirePerms;
import com.woniuxy.commons.utils.ResponseResult;

import com.woniuxy.myfinance.service.InandoutService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author author
 * @create 2021-11-16 16:56
 */
@RestController
@RequestMapping("/finance")
public class InandoutlogController {

    @Resource
    private InandoutService inandoutService;


    @LogRequirePerms(module = "财务模块",description = "查询财务记录")
    @RequirePerms("user:select")
    @GetMapping("/getallinandout")
    public ResponseResult getall(Inandoutlog inandoutlog, int pageIndex, int pageSize){
        List<Inandoutlog> inandoutlogs = inandoutService.selectAllInandoutlog(inandoutlog, pageIndex, pageSize);
        int i = inandoutService.selectInandoutlogCountBylimit(inandoutlog);
        PageBean pageBean=new PageBean();
        pageBean.setBeanList(inandoutlogs);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(i);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setCode(200);
        responseResult.setMessage("查询成功");
        responseResult.setData(pageBean);
        return responseResult;

    }

    @LogRequirePerms(module = "财务模块",description = "添加财务记录")
    @RequirePerms("user:add")
    @PostMapping("/addInandoutlogs")
    public ResponseResult addInandoutlogs(@RequestBody Inandoutlog inandoutlog){
     inandoutService.addInandoutlog(inandoutlog);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setCode(200);
        responseResult.setMessage("添加成功");

        return responseResult;



    }

    @LogRequirePerms(module = "财务模块",description = "修改财务记录")
    @RequirePerms("user:update")
    @PutMapping("/updateInandoutlogs")
    public ResponseResult updateInandoutlogs(@RequestBody Inandoutlog inandoutlog){
        inandoutService.updateInandoutlog(inandoutlog);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setCode(200);
        responseResult.setMessage("修改成功");
        return responseResult;

    }


    @LogRequirePerms(module = "财务模块",description = "删除财务记录")
    @RequirePerms("user:del")
    @DeleteMapping("/delInandoutlogs/{id}")
    public ResponseResult delInandoutlogs(@PathVariable("id") int id){
         inandoutService.delectInandoutlogByid(id);
        ResponseResult responseResult=new ResponseResult();
        responseResult.setCode(200);
        responseResult.setMessage("删除成功");
        return responseResult;

    }




}
